package com.A01.sys.service.impl;

import com.A01.sys.entity.UserEntity;
import com.A01.utils.ContextHolderUtils;
import org.apache.commons.lang3.StringUtils;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;
import com.baomidou.mybatisplus.mapper.EntityWrapper;
import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.mybatisplus.service.impl.ServiceImpl;
import com.A01.utils.PageUtils;
import com.A01.utils.Query;

import com.A01.sys.dao.EmployeeDao;
import com.A01.sys.entity.EmployeeEntity;
import com.A01.sys.service.EmployeeService;


@Service("employeeService")
public class EmployeeServiceImpl extends ServiceImpl<EmployeeDao, EmployeeEntity> implements EmployeeService {

    @Override
    public PageUtils queryPage(Map<String, Object> params) {
        String name = (String)params.get("name");
        EntityWrapper<EmployeeEntity> ew = new EntityWrapper<>();
        UserEntity user = ContextHolderUtils.getUser();
        if (user.getUserId() != 1) {
            ew.eq("company_id",user.getCompanyId());
        }
        ew.orderBy("status",false);
        ew.like(StringUtils.isNotBlank(name),"name",name);
        Page<EmployeeEntity> page = this.selectPage(
                new Query<EmployeeEntity>(params).getPage(),
                ew
        );

        return new PageUtils(page);
    }

    @Override
    public List<EmployeeEntity> listEmployee() {
        EntityWrapper<EmployeeEntity> ew = new EntityWrapper<>();
        UserEntity user = ContextHolderUtils.getUser();
        ew.eq("company_id",user.getCompanyId());
        ew.eq("status",2);
        return this.selectList(ew);
    }

}
